<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
	<head>

		<title>${projeto.nome}: ${requisito.tipo.nome}</title>

		<script type="text/javascript" src="/requisiteworks/scripts/editors.js" ></script>	
	</head>
	<body>
		<%@include file="painel-requisito.jsp" %>
		<div class="view-requisito full-height">
			<fieldset>
				<legend>${requisito.tipo.nome}</legend>
				
				<form:form commandName="" method="POST" modelAttribute="requisito" action="/requisiteworks/requisito/${projeto.numero}/salvaUpload.do" enctype="multipart/form-data">
					<input name="projeto" value="${projeto.numero}" type="hidden" />
					<input name="requisito" value="${requisito.numero}" type="hidden" />
					<input name="tipo" value="${requisito.tipo.numero}" type="hidden" />
					<table width="100%" class="form">
						<tr>
							<td>
								<form:label path="nome" cssErrorClass="erro">Nome: </form:label>
							</td>
							<td>
								<form:input  path="nome" cssErrorClass="erro" maxlength="128"/>
							</td>
							<td>
								<em>(campo obrigatorio)</em>
								<ul>
									<form:errors path="nome" cssClass="erro" element="li"></form:errors>
								</ul>
							</td>
						</tr>
						
						<tr>
							<td>
								<form:label path="responsavel.nome" cssErrorClass="erro">Responsavel: </form:label>
							</td>
							<td>
								<select name="responsavel.numero">
									<c:forEach items="${projeto.time.membros}" var="membro">
										<c:if test="${membro.numero eq requisito.responsavel.numero}" >
											<option value="${membro.numero}" selected="selected">${membro.nome}</option>
										</c:if>
										<c:if test="${not (membro.numero eq requisito.responsavel.numero)}" >
											<option value="${membro.numero}">${membro.nome}</option>
										</c:if>
									</c:forEach>								
								</select>
							</td>
							<td>
								<ul>
									<form:errors path="responsavel.nome" cssClass="erro" element="li"></form:errors>
								</ul>
							</td>
						</tr>
						
						<c:forEach items="${requisito.atributos}" var="atributo">
							<tr>
								<td>
									<label for="atributo[${atributo.tipo.numero}]">${atributo.tipo.nome}</label>
								</td>
								<td>
									<input class="${atributo.tipo.tipoDado}" type="text" name="atributo[${atributo.tipo.numero}]" value="${atributo.valor}" maxlength="128"/>
								</td>
								<td>
									<c:if test="${atributo.tipo.obrigatorio}">
										<em>(campo obrigatorio)</em>
									</c:if>
									<c:if test="${not empty errors and not empty errors[atributo.tipo.numero]}">
										<c:set value="${errors[atributo.tipo.numero]}" var="er" />
										<span class="erro">${er.mensagem}</span>
									</c:if>
								</td>
							</tr>
						</c:forEach>
						
						<tr>
							<td colspan="3" align="center">
								<label>Arquivo: </label><br />
								<input type="file" name="upload" />
							</td>
						</tr>
					</table>
					
				<button type="submit">Salvar</button>
				</form:form>
			</fieldset>
		</div>
	</body>
</html>